package com.talkology.pilot.teacher.service.impl;

import com.talkology.pilot.common.util.DateTimeUtil;
import com.talkology.pilot.database.dao.TeachersTimeMgtMapper;
import com.talkology.pilot.database.model.TeachersTimeMgt;
import com.talkology.pilot.teacher.service.ITeachersTimeMgtService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
public class TeachersTimeMgtServiceImpl implements ITeachersTimeMgtService {
    @Autowired
    private TeachersTimeMgtMapper mapper;

    @Override
    public List<TeachersTimeMgt> getAllByFilter(String name, String type) {
        Date data = null;
        if (name != null) {
            data = DateTimeUtil.dayAddNum(new Date(), 1);
        }
        return this.mapper.selectByFilter(name, type, data);
    }

    @Override
    public TeachersTimeMgt getInfo(Long index) {
        return this.mapper.selectByPrimaryKey(index);
    }

    @Override
    @Transactional
    public void add(TeachersTimeMgt record) {
        this.mapper.insert(record);
    }

    @Override
    @Transactional
    public void edit(TeachersTimeMgt record) {
        this.mapper.updateByPrimaryKey(record);
    }

    @Override
    @Transactional
    public void delete(Long index) {
        this.mapper.deleteByPrimaryKey(index);
    }
}
